package com.bjpowernode.crm.web.controller;

import com.bjpowernode.crm.mapper.UserMapper;
import com.bjpowernode.crm.pojo.Page;
import com.bjpowernode.crm.pojo.Role;
import com.bjpowernode.crm.pojo.User;
import com.bjpowernode.crm.service.QxService;
import com.bjpowernode.crm.service.UserService;
import com.bjpowernode.crm.utils.UUIDUtil;
import com.sun.javafx.collections.MappingChange;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("qx")
@ResponseBody
public class QxController {

    @Resource
    private QxService qxService;

    @Resource
    private UserService userService;
    //页面展示
    @RequestMapping("listQx.json")
    public Page getAllRole(Page page){
      qxService.getAllRole(page);//java是值传递，page传进去后，回来就是被修改的page。
        return page;
    }


    @RequestMapping("addQx.do")
    public Map addQx(Role role){
        role.setId(UUIDUtil.getUUID());
        qxService.addQx(role);


        return new HashMap(){{
            put("success",true);
            put("msg","添加成功！");
        }};
    }


    @RequestMapping("delQx.do")
    public Map delQx(String[] ids){

        qxService.delQx(ids);

        return new HashMap(){{
            put("success",true);
            put("msg","删除成功！");
        }};
    }


    @RequestMapping("listDetail.json")
    public Role getRole(String id){
        return qxService.getRole(id);
    }

    @RequestMapping("listUser.json")
    public Page getUser(Page page, @RequestParam Map map){
        userService.getUser(page,map);
        return page;
    }

    @RequestMapping("addUser.do")
    public Map addUser(User user){
        user.setId(UUIDUtil.getUUID());
        userService.addUser(user);
        return new HashMap(){{
            put("success",true);
            put("msg","添加成功！");
        }};
    }

    @RequestMapping("del.do")
    public Map delUser(String[] ids){
        System.out.println(ids);
        userService.delUser(ids);
        return new HashMap(){{
            put("success",true);
            put("msg","删除成功！");
        }};
    }

}
